package algorithm;

/**
 * @author Panbo Guo
 * @date 2021/7/7
 */
public class T00278 {

    public static void main(String[] args) {
        System.out.println(new Solution(2147483647).firstBadVersion(2147483647));
    }

    static class Solution {
        int badVersion;

        public Solution(int badVersion) {
            this.badVersion = badVersion;
        }

        public int firstBadVersion(int n) {
            int start = 0, end = n;
            while (start < end) {
                int mid = start + (end - start) / 2;
                if (isBadVersion(mid)) {
                    end = mid;
                } else {
                    start = mid + 1;
                }
            }
            return end;
        }

        public boolean isBadVersion(int version) {
            return version >= badVersion;
        }
    }
}
